package bg.cinema_system.service;

import java.sql.SQLException;
import java.util.List;

import bg.cinema_system.DAO.ReservationDAO;
import bg.cinema_system.DAO.SeatDAO;
import bg.cinema_system.DAO.UserInfoDAO;
import bg.cinema_system.DAO.UserTicketsDAO;
import bg.cinema_system.pojo.UserTickets;

public class UserTicketsService {

	public static List<UserTickets> getUserTicketsList(int user_id) throws SQLException {
		return UserTicketsDAO.getUserTicketsList(user_id);
	}

	public static String getUsername(int user_id) throws SQLException {
		return UserInfoDAO.getUsername(user_id);
	}

	public static int getUserId(String username) throws SQLException {
		return UserInfoDAO.getUserId(username);
	}

	public static String getEmail(String username) throws SQLException {
		return UserInfoDAO.getEmail(username);
	}

	public static String getRole(String username) throws SQLException {
		return UserInfoDAO.getRole(username);
	}

	public static void setRole(int user_id, int newRole) throws SQLException {
		UserInfoDAO.setRole(user_id, newRole);
	}

	public static boolean buyTicket(int user_id, int projection_id, int ticket_price) throws SQLException {
		boolean result = UserTicketsDAO.buyTicket(user_id, projection_id, ticket_price);
		
		int ticket_id = -1;
		int reservation_id = -1;
		
		if (result) {
			ticket_id = UserTicketsDAO.getTicketId(projection_id, user_id);
			reservation_id = ReservationDAO.getReservationId(projection_id, user_id);
			result = SeatDAO.buySeat(ticket_id, reservation_id);
		}
		
		return result;
	}
}
